package com.yanqu.road.dao.impl.activity.snowgarden;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.snowgarden.config.SnowGardenMapConfig;
import com.yanqu.road.entity.activity.snowgarden.config.SnowGardenShowConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SnowGardenShowConfigDaoImpl extends TempDao {

    private static String getSnowGardenShowConfigSql = "select * from `t_s_activity_snowgarden_show` where `activityId`=?";

    public Map<Integer, SnowGardenShowConfig> getSnowGardenShowConfig(int activityId){
        Map<Integer, SnowGardenShowConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSnowGardenShowConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SnowGardenShowConfig snowGardenShowConfig = new SnowGardenShowConfig();
                snowGardenShowConfig.setActivityId(rs.getInt("activityId"));
                int id = rs.getInt("quality");
                snowGardenShowConfig.setQuality(id);
                snowGardenShowConfig.setRoleId(rs.getInt("roleId"));
                snowGardenShowConfig.setName(rs.getString("name"));
                snowGardenShowConfig.setDesc(rs.getString("desc"));
                snowGardenShowConfig.setWeight(rs.getInt("weight"));
                map.put(id, snowGardenShowConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
